<?php

namespace app\admin\controller;

use app\admin\logic\DiseaseCategoryLogic;
use app\common\respond\HttpApi;

class DiseaseCategoryController
{
    /**
     * @Description 列表
     * @author: zj
     * @param HttpApi $respond
     * @time 2024/03/28 15:37:26
     * @return \think\response\Json
     */
    public function list(HttpApi $respond)
    {
        $param = [
            'page' => (int)request()->get('page') ?: 1,
            'page_size' => (int)request()->get('page_size') ?: 10,
            'name' => request()->get('name')
        ];
        $rule = [
            'page' => 'require|integer|>:0',
            'page_size' => 'require|integer|>:0',
            'name' => 'integer|max:255',
        ];
        validate($rule)->check($param);

        $logic = new DiseaseCategoryLogic();
        $data = $logic->getList($param);

        return $respond->success($data);
    }

    /**
     * @Description 新增
     * @author: zj
     * @param HttpApi $respond
     * @time 2024/03/28 15:46:16
     * @return \think\response\Json
     */
    public function add(HttpApi $respond)
    {
        $param = [
            'name' => request()->post('name'),
        ];
        $rule = [
            'name' => 'require|max:255'
        ];
        validate($rule)->check($param);

        $logic = new DiseaseCategoryLogic();
        $data = $logic->add($param);

        return $respond->success([]);
    }

    /**
     * @Description 删除
     * @author: zj
     * @param HttpApi $respond
     * @time 2024/03/28 15:51:48
     * @return \think\response\Json
     */
    public function del(HttpApi $respond)
    {
        $param = [
            'id' => request()->post('id'),
        ];
        $rule = [
            'id' => 'require|max:255'
        ];
        validate($rule)->check($param);

        $logic = new DiseaseCategoryLogic();
        $data = $logic->del($param['id']);

        return $respond->success([]);
    }

}